<?php
/**
 * Created by PhpStorm.
 * User: sqq
 * Date: 2018/11/15
 * Time: 11:07
 * Description：历史优惠券生成张数同步到新表（执行一次即可，禁止重复执行）
 */
$service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($service_path . "public/index.php");
ob_end_clean();

echo date('Y-m-d H:i:s',time())." coupon increment cancel started \n";

//查询历史优惠券
$coupon = CouponBaseInfo::select('id','created_at','count','created_by','num_type')->get();
if(!is_null($coupon)){
    foreach($coupon as $key => $val){
        $coupons = new CouponIncrement();
        $coupons->coupon_base_info_id = $val->id;
        $coupons->count = $val->count;
        $coupons->created_at = $val->created_at;
        $coupons->updated_at = $val->created_at;
        $coupons->created_by = $val->created_by;
        $coupons->type = 1;
        $coupons->num_type = $val->num_type;
        $coupons->status = 1;
        try{
            $coupons->save();
        } catch (Exception $e) {
            print_r($e);
            Log::error(json_encode($e));
        }
    }
}

echo date('Y-m-d H:i:s',time())." coupon increment retry stoped \n";